﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microhard.Permission.Models;
using Microhard.Core.DBUtility;
using Microsoft.Practices.EnterpriseLibrary.Caching;

namespace Microhard.Permission
{
    public class LogonUserInfoCache : ICacheOperator<User>
    {
        private ICacheManager cm = CacheFactory.GetCacheManager("logonUserInfo");
        public void UpdateCache(string key, User newModel)
        {
            cm.Add(key, newModel);
        }

        public User GetFromCache(string key)
        {
            User rtn = new User();
            if (string.IsNullOrEmpty(key))
                return rtn;
            rtn = cm.GetData(key) as User;
            return rtn;
        }

        public void RemoveFormCache(List<string> keys)
        {
            if (keys == null)
                return;
            foreach (var k in keys)
            {
                cm.Remove(k);
            }
        }

        public void RefreshCache()
        {
            cm.Flush();
        }
    }
}
